﻿///<author>Arjen van Zanten</author>
///<datecreated>2012-03-28</datecreated>
///<summary>Basic rasterized Otsu testing class. Does not work any better than regular Otsu, and is considerably slower, but does have potential.</summary>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace THO7_Team8
{
    public class OtsuRasterized
    {
        /// <summary>
        /// Returns a binarized copy of the given Bitmap, using Otsu's Thresholding a raster with the given cols and rows.
        /// </summary>
        /// <param name="bmp">Input Bitmap</param>
        /// <param name="cols">Number of raster colums</param>
        /// <param name="rows">Number of raster rows</param>
        /// <returns>The binarized copy</returns>
        public static Bitmap Apply(Bitmap bmp, int cols, int rows)
        {
            RasterizedImage rasterizedImage = new RasterizedImage(bmp, cols, rows);

            foreach (Bitmap section in rasterizedImage.Sections)
            {
                GrayscaleHistogram hist = new GrayscaleHistogram(section);
                BitmapProcessor.Threshold(section, Otsu.SinglePass(hist.Array));
            }

            return rasterizedImage.GetRestoredBitmap();
        }
    }
}
